<template>
  <div class="login-container" ref="login" @keyup.enter.native="handleLogin" style="display: flex">

    <div class="left-box">
      <div class="left-title">
        <img src="favicon.png"/>
        <span>监狱档案 | 管理平台</span>
      </div>
      <div class="left-img">
        <img src='img/bg/login-left.png'/>
      </div>
    </div>

    <div class="right-box">
      <div class="login-border" style="width: 65%">
        <div class="login-main">
          <div style="display: flex;justify-content: space-around;margin-bottom: 50px">
            <div style="color: black;display: flex;align-items: center;">
              <img src="favicon.png" height="50px"/>
              <div style="margin-left: 10px">
                <div style="font-size: 22px;font-weight: bold;letter-spacing: 6px">档案管理</div>
                <div style="font-size: 8px;margin-top: 5px">DANG AN GUAN LI</div>
              </div>
            </div>
          </div>

          <userLogin v-if="activeName === 'user'"></userLogin>
          <codeLogin v-else-if="activeName === 'code'"></codeLogin>
        </div>
      </div>
    </div>




  </div>
</template>
<script>
import userLogin from "./userlogin";
import codeLogin from "./codelogin";
import thirdLogin from "./thirdlogin";
import { mapGetters } from "vuex";
import { dateFormat } from "@/util/date";
import { validatenull } from "@/util/validate";
import topLang from "@/page/index/top/top-lang";
import topColor from "@/page/index/top/top-color";
import { getQueryString, getTopUrl } from "@/util/util";

export default {
  name: "login",
  components: {
    userLogin,
    codeLogin,
    thirdLogin,
    topLang,
    topColor,
  },
  data() {
    return {
      time: "",
      activeName: "user",
      socialForm: {
        tenantId: "000000",
        source: "",
        code: "",
        state: "",
      },
    };
  },
  watch: {
    $route() {
      this.handleLogin();
    },
  },
  created() {
    localStorage.clear();
    this.handleLogin();
    this.getTime();
  },
  mounted() {},
  computed: {
    ...mapGetters(["website", "tagWel"]),
  },
  props: [],
  methods: {
    getTime() {
      setInterval(() => {
        this.time = dateFormat(new Date());
      }, 1000);
    },
    handleLogin() {
      const topUrl = getTopUrl();
      const redirectUrl = "/oauth/redirect/";
      this.socialForm.source = getQueryString("source");
      this.socialForm.code = getQueryString("code");
      this.socialForm.state = getQueryString("state");
      if (
        validatenull(this.socialForm.source) &&
        topUrl.includes(redirectUrl)
      ) {
        let source = topUrl.split("?")[0];
        source = source.split(redirectUrl)[1];
        this.socialForm.source = source;
      }
      if (
        !validatenull(this.socialForm.source) &&
        !validatenull(this.socialForm.code) &&
        !validatenull(this.socialForm.state)
      ) {
        const loading = this.$loading({
          lock: true,
          text: "第三方系统登录中,请稍后。。。",
          spinner: "el-icon-loading",
        });
        this.$store
          .dispatch("LoginBySocial", this.socialForm)
          .then(() => {
            window.location.href = topUrl.split(redirectUrl)[0];
            this.$router.push({ path: this.tagWel.value });
            loading.close();
          })
          .catch(() => {
            loading.close();
          });
      }
    },
  },
};
</script>

<style lang="scss">
@import "@/styles/login.scss";


.left-box{
  width: 60%;
  height: 100%;
  background-size: 100% 100%;
  background: linear-gradient(to right,#495875, #7692C4);
  .left-title{
    display: flex;
    align-items: center;
    font-weight: bold;
    font-size: 20px;
    padding: 30px 20px 20px 20px;
    width: 100%;
    color: white;
    img{
      height: 36px;
      width: 40px;
      margin: 0 10px;
    }
  }
  .left-img{
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: 95%;
    img{
      margin-bottom: 100px;
      width: 800px;
      border-radius: 20px;
    }
  }
}

.right-box{
  width: 40%;
  height: 100%;
  padding-left: 10px;
  background: linear-gradient(to bottom,#A7BEE7, #617EB6);
  display: flex;
  align-items: center;
  justify-content: space-around
}



.login-border{
  background-color: white;
  opacity: 0.9;
  border-radius: 20px;
}

</style>
